package Common;

import Database.Document;
import java.util.Vector;
import Query.SearchEnginesTypes;

public class Intersection {
    
    private static Vector<Document> Intersect(Vector<Vector<Document>> documents)
    {
        Vector<Document> result = new Vector<Document>();
        for(int i = 0; i < documents.size(); i++)
            for(int j = 0; j < documents.get(i).size(); j++)
            {
                Document current = documents.get(i).get(j);
                for(int k = 0; k < documents.size(); k++)
                {
                    if(k == i)
                        continue;
                    for(int l = 0; l < documents.get(k).size(); l++)
                    {
                        if(current.equals(documents.get(k).get(l)))
                        {
                            boolean flag = false;
                            
                            for(int m = 0; m < result.size(); m++)
                                if(current.equals(result.get(m)))
                                {
                                    flag = true;
                                    break;
                                }
                            if(!flag)
                                result.add(current);
                        }
                    }
                }
            }
        return result;
    }
    
    public static Vector<Document> IntersectDocuments(Vector<Vector<Document>> documents)
    {
        return Intersect(documents);
    }
    
    public static int IntersectDocumentsSize(Vector<Vector<Document>> documents)
    {
        Vector<Document> tmp = Intersect(documents);
        return tmp.size();
    }
}
